
require "Object"
--Player class
WorldMap = Object:new{
	
}

function WorldMap:onEnter()
	Misc:log("WorldMap : onEnter .. " .. Misc:getNodeName(self))
	
	--regist the back button event
	local backBtn = tolua.cast(Misc:getChildByName(self, "backBtn"), "CCMenuItemLabel")
	local function clickBackBtn()
		self:clickBackBtn()
	end
	backBtn:registerScriptHandler(clickBackBtn)
	
end

function WorldMap:clickBackBtn()
	self:removeFromParentAndCleanup(true)
end
	
function WorldMap:onExit()
	CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry(self.updateID)
end

function WorldMap:create(mapFile)
	local worldMap = WorldMap:new()
	--self.__index = self
	
	local cc2dNode = CC2DFileCache:sharedCC2DFileCache():addCC2DNode(mapFile)
	local ccWorldMap = tolua.cast(cc2dNode:createCCNode(CCDirector:sharedDirector():getRunningScene()), "CCLayer")
	Misc:setNodeName(ccWorldMap, "world-map")
	
	tolua.setpeer(ccWorldMap, worldMap)
	
	local function onEnterOrExit(eventType)
		if eventType == kCCNodeOnExit then
			ccWorldMap:onExit()
		else
			ccWorldMap:onEnter()
		end
	end
	
	ccWorldMap:registerScriptHandler(onEnterOrExit)
	
	if ccWorldMap:isRunning() then
		ccWorldMap:onEnter()
	end
	return ccWorldMap
end